﻿using EasyPhysic.Collider;
using NativeTrees;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;

namespace EasyPhysic.Job
{
    [BurstCompile]
    public struct UpdateTreeJob : IJob
    {
        
        
        public NativeArray<ColliderBody> _colliderBodyList;
        public NativeQuadtree<int> quadtree;
        [BurstCompile]
        public void Execute()
        {
            quadtree.Clear();
            for (int i = 0; i < _colliderBodyList.Length; i++)
            {
                var collider=_colliderBodyList[i];
                if (collider.IsValid)
                {
                    quadtree.Insert(_colliderBodyList[i].SerialId, _colliderBodyList[i].Bound);
                }
            }
        }
    }
}